/*
Minims .Net Playstation 3 UPNP ContentDirectory
Copyright (C) 2008  Guillaume Plourde

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/


using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace minims
{
	public partial class MainDialog : Form
	{
		Hashtable services;
		SSDP_SERVER ssdp_server;
		HTTP_SERVER http_server;

		bool ServerStarted;

		public MainDialog()
		{
			InitializeComponent();
			//http_server.AccessUpdatedEvent += new HTTP_SERVER.AccessUpdatedDelegate(OnAccessListUpdated);
		}
		private void c_CloseButton_Click(object sender, EventArgs e)
		{

		}
		private void c_StartButton_Click(object sender, EventArgs e)
		{
			if (!ServerStarted)
			{
				ServerStarted = true;
				c_StartButton.Text = "Stop";
				c_StartButton.Image = global::minims.Properties.Resources.process_stop;

				services = new Hashtable();
				//http_server = new HTTP_SERVER(services, 80);
				ssdp_server = new SSDP_SERVER();

				List<string> folders = new List<string>();
				foreach (ListViewItem item in c_FolderList.Items)
				{
					folders.Add(item.Text);
				}
				services.Add("ContentDirectory", new ContentDirectory(folders));

				ssdp_server.Start();
				http_server.Start();
			}
			else
			{
				ServerStarted = false;
				c_StartButton.Text = "Start";
				c_StartButton.Image = global::minims.Properties.Resources.media_playback_start;

				http_server.Stop();
				ssdp_server.Stop();

				services = null;
				ssdp_server = null;
				http_server = null;
			}
		}
		private void c_AddFolder_Click(object sender, EventArgs e)
		{
			c_SharedFolderBrowser.ShowDialog();
			
			if (c_SharedFolderBrowser.SelectedPath != "")
				c_FolderList.Items.Add(c_SharedFolderBrowser.SelectedPath, "folder.png");
		}

		private void OnAccessListUpdated(object sender, EventArgs e)
		{
			
		}
	}
}